﻿var hikApiPreView = {
	option:{
		id:"",
		num:0,
		wnds:4
	},
	getActiveX : function() {
		var _this=this;
		var ocx =document.getElementById(_this.option.id);
		return ocx;
	},
	setLocalParams : function() {//设置本地参数
		_this =this;
		var ocxObj = _this.getActiveX();
		var devPxRa = screen.deviceXDPI / screen.logicalXDPI;
		var height = ocxObj.height * devPxRa;
		var width = ocxObj.width * devPxRa;
		var xml = '<?xml version="1.0" encoding="UTF-8"?> ' 
				+ '<localParam> '
				+ '<width>' + width + '</width> '
				+ '<height>' + height + '</height> '
				+ '<picType>0</picType> '
				+ '<capturePath>C:\\Hikvision</capturePath> '
				+ '<recordSize>2</recordSize> '
				+ '<recordPath>C:\\Hikvision</recordPath> '
				+ '<limitPreviewTime>0</limitPreviewTime> '
				+ '<showMsgTip>0</showMsgTip></localParam>';
		var ret = ocxObj.MPV_SetLocalParam(xml);
		return ret;
	},
	init : function() {//初始化
		var _this=this;
		var ocxObj = _this.getActiveX();
		var languageType = 1;
		var ret =ocxObj.MPV_Init(languageType);
		_this.setLocalParams();
		_this.setMainMenuBar();
		_this.setMenuBar();
		_this.setPlayWindowCount();
		
		if (ret != 0) {
			alert("初始化失败");
		}else if(localParams!=0){
			alert("设置本地参数失败");
		} 
	},
	startPreview:function(resourceId) {//预览
		var _this=this;
		$.ajax({
			url : "/hikapi/live-preview",
			type : "POST",
			data : {
				"carmerId": resourceId,
			},
			success : function(data) {
				if (data&& data.data) { // 调OCX预览接口
					var ret = _this.getActiveX().MPV_StartPreview(data.data);
					if (ret != 0) {
						alert("预览失败：" + data.data);
					}
				} else {
					var vDesc = "查询预览参数失败,请检查接口参数！ ";
					alert(vDesc);
				}
			},
		 
		});
		
	},
	setPlayWindowCount:function(){
		_this =this;
		var ret = _this.getActiveX().MPV_SetPlayWndCount(parseInt(_this.option.wnds, 10));
		if(ret!=0){
			alert("设置分屏失败!");
		}
	},
	getPlayWindowCount:function(){
		_this =this;
		return _this.getActiveX().MPV_GetPlayWndCount();
	},
	pause:function(){//暂停
		clearInterval(timer);
	},
	setMenuBar:function(){//隐藏插件工具栏
		_this =this; 
		var ids="0,1,2,3,4,5,6,7,9,10,11,12,13,14";//关闭预览按钮
		var ret =  _this.getActiveX().MPV_SetToolBar(ids);
		if (ret != 0) {
			alert("自定义播放工具条按钮失败！");
		}
	},
	setMainMenuBar:function(){
		_this =this;
		var ids="0,1,2,3,4,5,6";//全屏
		var ret =  _this.getActiveX().MPV_SetMainToolBar(ids);
		if (ret != 0) {
			alert("隐藏主工具栏失败");
		}
	}
}
